package shop

import (
	"context"
	"fast-boot/app/api/admin/internal/svc"
	"fast-boot/app/api/admin/internal/types"
	"fast-boot/app/model"
	"fast-boot/common/xerr"

	"github.com/zeromicro/go-zero/core/logx"
)

type BrandUpdateLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

// 修改Brand
func NewBrandUpdateLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BrandUpdateLogic {
	return &BrandUpdateLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BrandUpdateLogic) BrandUpdate(in *types.BrandForm) (resp *types.BrandFormResp, err error) {

	info := model.PmsBrandModel{}
	l.svcCtx.GormClient.GormDb.First(&info, in.Id)

	if info.Id == 0 {
		logx.WithContext(l.ctx).Errorf("不存在: %s", in.Id)
		return nil, xerr.NewErrMsg("不存在")
	}
	info.ShopId = in.ShopId
	info.Name = in.Name
	info.Logo = in.Logo
	info.Sort = in.Sort
	err = l.svcCtx.GormClient.GormDb.Save(&info).Error

	return &types.BrandFormResp{
		Id: info.Id,
	}, nil
}
